package com.scs.application.modules.sys.controller;

import com.scs.application.core.mvc.controller.CrudController;
import com.scs.application.modules.sys.dto.SaveAuthorityDTO;
import com.scs.application.modules.sys.entity.Authority;
import com.scs.application.modules.sys.model.RestResult;
import com.scs.application.modules.sys.service.AuthorityService;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 */
@RestController
@RequestMapping("/authority")
public class AuthorityController extends CrudController<AuthorityService,Authority> {


    /**
     * 根据roleID查找数据
     */
    @GetMapping(value = "/role/{roleId}")
    public RestResult getRoleAuthority(@PathVariable("roleId") String roleId){
        List<Authority> result = service.getRoleAuthority(roleId);
        return RestResult.ok("获取数据成功", result);
    }

    /**
     * 保存角色权限
     */
    @PostMapping(value = "/role/save")
    public RestResult saveAuthority(@RequestBody SaveAuthorityDTO entity){
        boolean isOk = service.saveAuthority(entity);
        if(!isOk){
            return RestResult.error("数据保存失败！");
        }
        return RestResult.ok("数据保存成功");
    }


    /**
     * 角色维护界面，给角色添加菜单权限
     */
    /**
    * @Description：角色维护界面，给角色添加或者删除菜单权限
    */
    @PostMapping(value = "/role/addOrDeleteMenus")
    synchronized  public RestResult addOrDeleteMenus(@RequestBody Map<String, String> reqData){
        service.addOrDeleteMenus(reqData);
        return RestResult.ok();
    }

    /**
     * 添加删除菜单
     */
    @RequestMapping(value = "/addOrDelete", method = RequestMethod.POST)
    public RestResult addOrDelete(@RequestBody Map<String, Object> para){
        service.addOrDelete(para.get("roleId")+"", para.get("addMenuIds")+"", para.get("deleteMenuIds")+"");
        return RestResult.ok("用户添加成功");
    }

}
